package Admin

import (
	"autoDeploy/service/AdminDocker"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

// GetTeams 加载管理员界面项目资源
func (ad Admin) GetTeams(c *gin.Context) {
	//调用service层方法获取团队的数据
	TeamMsg, err := AdminDocker.GetTeams()
	if err != nil {
		c.JSON(200, gin.H{"code": 0, "teams": TeamMsg, "message": "获取信息失败"})
		return
	} else {
		c.JSON(200, gin.H{"code": 1, "teams": TeamMsg, "message": "获取信息成功"})
		return
	}

}

// DeleteTeam 管理员解散团队
func (a Admin) DeleteTeam(c *gin.Context) {
	//解析前端发来的数据
	teamIDStr := c.Query("team_id")
	projectIDStr := c.Query("project_id")
	address := c.Query("address")
	// 将字符串转换为 uint64
	teamID, err := strconv.ParseUint(teamIDStr, 10, 64)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid team_id"})
		return
	}

	projectID, err := strconv.ParseUint(projectIDStr, 10, 64)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid project_id"})
		return
	}
	//调用service层中的方法
	err = AdminDocker.DeleteTeam(teamID, projectID, address)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"code": 0, "message": err.Error()})
		return
	}

	c.JSON(200, gin.H{"code": 1, "message": "解散成功"})
	return
}
